package com.elm.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.elm.model.User;
import com.elm.service.UserService;
import com.elm.serviceimpl.UserServiceImpl;

public class UserRegistController extends HttpServlet{
	UserService us = new UserServiceImpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		String username= req.getParameter("username");
		String userpsw= req.getParameter("userpsw");
		String userphone= req.getParameter("userphone");
		String useraddr= req.getParameter("useraddr");
		User user = new User(username, userpsw, userphone, useraddr);
		boolean flag = us.userRegist(user);
		if(flag){
			req.getRequestDispatcher("regist.jsp").forward(req, resp);
		}
	}
}
